<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            选择物料
        </div>
    </header>
    <script id="mrlTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setMrl('{{= it[index].sysid }}','{{= it[index].code }}','{{= it[index].name }}');">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-title">{{= it[index].code }}:{{= it[index].name }}</div>
            </div>
        </li>
        {{~}}

    </script>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:getMrlList();">
                        <input type="search" placeholder="请输入物料编码/名称" id="codeOrName">
                    </form>
                </div>
                <!-- <i class="aui-iconfont aui-icon-roundclosefill" tapmode onclick="clearInput()"></i> -->
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4" onclick="getMrlList()">搜索</div>
        </div>
        <ul class="aui-list aui-list-in" id="mrlList">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<!-- <script src="../script/zepto.min.js"></script> -->
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    apiready = function() {

        // getMrlList();

    };

    //查询仓库列表
    function getMrlList() {
        var codeOrName= $("#codeOrName").val();
        if (codeOrName == "" || codeOrName == null || codeOrName == undefined) {
            api.toast({
                msg: '请输入查询关键字',
                duration: 3000
            });
            return;
        }
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdMrlList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                codeOrName: codeOrName,
                appVersion: api.appVersion,

                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var mydata = myobj.list;
                    var evaluation = doT.template($api.dom('#mrlTemp').innerHTML);
                    $api.dom('#mrlList').innerHTML = evaluation(mydata);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选则返回函数
    function setMrl(mrlId, mrlCode, mrlName) {
        api.closeWin();
        var name = api.pageParam.name;

        api.execScript({
            name: name,
            script: 'setMrl("' + mrlId + '","' + mrlCode + '","' + mrlName + '")'
        });


    }

    //库位编码查询
    // function doSearch() {
    //
    //     var workCellCodeS = $("#workCellCodeS").val();
    //     var un = localStorage.getItem("un");
    //     var serverUrl = localStorage.getItem('serverUrl');
    //     var url = serverUrl + "/app/getMdMrlList";
    //     var data = {
    //         values: { ////以表单方式提交参数（JSON对象）
    //           codeOrName: codeOrName,
    //           un: un
    //         }
    //     };
    //     api.ajax({
    //         url: url,
    //         method: 'post',
    //         dataType: 'json',
    //         timeout: 30,
    //         returnAll: false,
    //         data: data
    //     }, function(ret, err) {
    //         if (ret) {
    //             var data = JSON.stringify(ret);
    //             var myobj = eval("(" + data + ")");
    //             if (myobj.code == '0') {
    //                 var mydata = myobj.list;
    //                 var evaluation = doT.template($api.dom('#mrlTemp').innerHTML);
    //                 $api.dom('#mrlList').innerHTML = evaluation(mydata);
    //             } else {
    //                 api.toast({
    //                     msg: myobj.message,
    //                     duration: 3000
    //                 });
    //             }
    //         }
    //     });
    // }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
